﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Reflection;
using Pixysoft.Weblications.Sango.Dao;
using Pixysoft.Weblications.Sango.Protocol.party;
using Pixysoft.Weblications.Sango.Formular;
using Pixysoft.Weblications.Sango.Protocol;
using Pixysoft.Weblications.Sango.Environment;
using Pixysoft.Weblications.Sango.Protocol.player;
using System.Data;

namespace Pixysoft.Weblications.Sango.Command.party
{
    partial class SangoPartyHandler
    {
        private const int party_memberlist_pageindex = 0;

        public party_memberlist party_memberlist()
        {
            string userCode = SangoManager.Authentication();

            party_memberlist response = ReflectionManager.CreatePojo<party_memberlist>();
            response.Succeed = false;

            Entities.Usr_Profile profile = UsrProfileDao.getUsrProfile(userCode);

            Entities.Usr_Partymember member = PartyDao.tryGetActiveMember(userCode);

            if (member == null)
            {
                response.Message = "尚未加入军团";
                return response;
            }

            Entities.Usr_Party party = PartyDao.tryGetActiveParty(member.Partyprimarycode);

            DataTable members = PartyDao.getActiveProfilesExcluded(member.Partyprimarycode, party_memberlist_pageindex, userCode);

            Entities.Pty_Partytitle position = PtyPartyTitleHelper.searchByCode(member.Titletypecode);
            int myRank = PartyDao.getMemberRanking(member.Partyprimarycode, member.Partycontributionvalue);
            int totalMembers = PartyDao.getTotalActiveMembers(party.Primarycode);
            int upgradeRank = (int)PartyFormular.getUpgradeRequiredRanking(position, totalMembers);

            response.rank = myRank;
            response.upgraderank = upgradeRank;
            response.mymember = PartyFacade.ToPartyMember(profile, party, member);
            response.members = PartyFacade.ToListMembers(members);
            response.Succeed = true;
            return response;
        }


    }
    public interface party_memberlist : ISangoResponse
    {
        List<party_listmember> members { get;set;}

        party_member mymember { get;set;}

        long rank { get;set;}

        long upgraderank { get;set;}
    }
}
